'''部门相关的接口描述'''
import requests

from interface_practice.frame.apis.wework import WeWork


class Department(WeWork):
    def create(self,create_data):
        '''
        创建部门
        '''
        url = f"https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token={self.access_token}"
        req = {
            "method": "POST",
            "url": url,
            "json": create_data
        }
        # create_result = requests.request("POST", url, json=create_data)
        create_result = self.send_api(req)
        return create_result

    def update(self,update_data):
        '''
        更新部门
        '''
        update_url = f"https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token={self.access_token}"
        req = {
            "method": "POST",
            "url": update_url,
            "json": update_data
        }
        update_result = self.send_api(req)
        # update_result = requests.request("POST", url=update_url, json=update_data)
        return update_result

    def delete(self,depart_id):
        '''
        删除部门
        '''
        delete_url = f"https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token={self.access_token}&id={depart_id}"
        req = {
            "method": "GET",
            "url": delete_url
        }
        delete_result = self.send_api(req)
        # delete_result = requests.request("GET", delete_url)
        return delete_result

    def get(self):
        '''
        查询部门
        '''
        list_url = f"https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token={self.access_token}"
        # list_result = requests.request("GET", url=list_url)
        req = {
            "method": "GET",
            "url": list_url
        }
        list_result = self.send_api(req)
        return list_result
